#coding=utf-8
"""
dashboard的页面渲染
"""
from cookies import Cookies, Cookie
from tornroutes import route
from react.conf import settings
import logging
from .base import BaseHandler
from ..tools import unblock, render

# 取得logger
logger = logging.getLogger('DashboardHandler')

@route('/dashboard')
class DashboardHandler(BaseHandler):
    """
    登陆页面
    """
    @unblock
    def get(self):
        if settings.RENDER:
            #persist_state = self.get_cookie('persist-state')
            # 构建新的cookie
            # cookies = Cookies('persist-state', persist_state)
            cookies = Cookies.from_response(self.cookies.output())
            logger.debug(cookies)
            #cookie['persist-state'] = persist_state
           # request_headers = {'Cookie': cookies.request_headers()}
            cookies['persist-state'].render_request();
            request_headers = {'Cookie': cookies['persist-state'].render_request()}
            logger.debug(request_headers)
            rendered = render(
                '/dashboard',
                {},
                to_static_markup=False,
                request_headers=request_headers
            )
            self.render('render.html', rendered=rendered)
        else:
            self.render("index.html")
